package self.wiki.controller;

import org.markdown4j.Markdown4jProcessor;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;

/**
 * Created by werewolf on 2017/7/25.
 */
@Controller
public class ApiController {

    @RequestMapping("")
    public String app() {
        return "index";
    }


    @RequestMapping("/api")
    @ResponseBody
    public Object api(@RequestParam(required = false) String service, @RequestParam(required = false) String version) {
        try {
            return new HashMap() {{
                put("status", 200);
                if (null == Application.files.get(service + ".md")) {
                    put("html", "接口文档未定义");
                } else {
                    put("html", new Markdown4jProcessor().process(Application.files.get(service + ".md")));
                }

            }};
        } catch (Exception e) {
        }
        return new HashMap() {{
            put("status", 200);
            put("html", "接口文档未定义");
        }};
    }
}
